import java.util.regex.Pattern;

public class Contact {

  private String name;

  private String email;

  private String phone;

  private String street;

  private String city;

  private String zip;

  private String country;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getPhone() {
    return phone;
  }

  public void setPhone(String phone) {
    this.phone = phone;
  }

  public String getStreet() {
    return street;
  }

  public void setStreet(String street) {
    this.street = street;
  }

  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }

  public String getZip() {
    return zip;
  }

  public void setZip(String zip) {
    this.zip = zip;
  }

  public String getCountry() {
    return country;
  }

  public void setCountry(String country) {
    this.country = country;
  }

  public static Contact formatContact(String str) {
    String[] params = str.split(";");
    return formatContact(params);
  }

  public static Contact formatContact(String[] array) {
    Contact contact = new Contact();
    for (String param : array) {
      boolean isNameMatch = Pattern.matches("^[A-Z][a-z]*(\\s[A-Z][a-z]*)*$", param);
      if (isNameMatch && contact.getName() == null) {
        contact.setName(param);
        continue;
      }

      boolean isEmailMatch = Pattern
          .matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", param);
      if (isEmailMatch) {
        contact.setEmail(param);
        continue;
      }

      boolean isPhoneMatch = Pattern.matches("^\\d{3}-\\d{3,8}$", param);
      if (isPhoneMatch) {
        contact.setPhone(param);
        continue;
      }

      boolean isStreetMatch =
          param.toLowerCase().contains("av.")
              || param.toLowerCase().contains("avenue")
              || param.toLowerCase().contains("street")
              || param.toLowerCase().contains("road");
      if (isStreetMatch) {
        contact.setStreet(param);
        continue;
      }

      boolean isCityMatch = Pattern.matches("^[A-Z][a-z]*(\\s[A-Z][a-z]*)*$", param);
      if (isCityMatch) {
        contact.setCity(param);
        continue;
      }

      boolean isZipMatch = Pattern.matches("^\\d{5}(-\\d{4})?$", param);
      if (isZipMatch) {
        contact.setZip(param);
        continue;
      }

      boolean isCountryMatch = true;
      if (isCountryMatch) {
        contact.setCountry(param);
      }
    }
    return contact;
  }
}
